import { http } from '@/utils/http';
import type {DetailArticle} from '@/type/article'
import type {QuestionDetail,QuestionItem,QuestionRecord} from '@/type/question'
import type {interviewItem,interviewDetail} from '@/type/interview'
/**
 * 根据文章标题模糊查询（帖子）
 *  @param {string} keyword 关键字
 * @param {number} orderType 查询的类型： 0表示按时间降序，1表示按浏览量降序，2表示按点赞数降序
 */
export const API_articleSearch = (keyword: string, orderType: number) => {
	return http<DetailArticle[]>({
		method: 'GET',
		url: `/article/search?keyword=${keyword}&orderType=${orderType}`
	})
}

/**
 * 根据八股问题部分模糊查询（话题）
 *  @param {string} keyword 关键字
 * @param {number} orderType 查询的类型：0表示按时间降序，1表示按浏览量降序，2表示按重要等级降序
 */
export const API_integratedQuestionSearch = (keyword: string, orderType: number) => {
	return http<interviewItem[]>({
		method: 'GET',
        url: `/integratedQuestion/search?keyword=${keyword}&orderType=${orderType}`
	})
}

/**
 * 根据选择题题干部分模糊查询
 *  @param {string} keyword 关键字
 * @param {number} orderType 查询的类型：0表示按时间降序，1表示按浏览量降序
 */
export const API_choiceQuestionSearch = (keyword: string, orderType: number) => {
	return http<any>({
		method: 'GET',
		url: '/choiceQuestion/search',
		data: {
			keyword,
			orderType
		}
	})
}
// 根据id查看单个题目内容
export const API_getQuestionDeatil = (id: number) => {
	return http<QuestionDetail>({
		method: 'GET',
	    url: `/choiceQuestion/getSingleChoiceQuestion?id=${id}`,
	  })
	}

//练习记录
export const API_getExerciseSet = () => {
	    return http<QuestionRecord[]>({
	        method: 'GET',
	        url: `/choiceQuestion/getExerciseSet`,
	    })
	}
//错题集
export const API_getMistakeCollection = () => {
    return http<QuestionItem[]>({
		method: 'GET',
		url: `/choiceQuestionRecord/getErrorSet`,
	})
}

// 获取热门题库（前10类）
export const API_getHotChoiceQuestionList = () => {
	return http<any>({
		method: 'GET',
		url: '/choiceQuestion/getHotChoiceQuestionList',
	})
}


// 根据id查看单个题目内容
export const API_getChoiceQuestion = (category: number, page: number) => {
	return http<any>({
		method: 'GET',
		url: `/choiceQuestion/getChoiceQuestion`,
		data: {
			category,
			page
		}
	})
}

// 题目作答
export const API_submitAnswer = (id: number, answer: string, choice_time: string) => {
    return http<string>({
		method: 'POST',
		url: `/choiceQuestionRecord/submitAnswer`,
		data: {
			id,
			answer,
			choice_time
		}
	})
}

// 添加收藏
export const API_addFavorite = (data:{ content_id: number, collection_name: string, collect_time: string, module: number }) => {
    return http<string>({
		method: 'POST',
		url: `/favorite/addFavorite`,
		data: data
	})
}

// 移除收藏
export const API_deleteFavorite = (data:{ content_id: number, module: number }) => {
    return http<string>({
		method: 'DELETE',
		url: `/favorite/deleteFavorite`,
		data: data
	})
}

// 获取单条八股题数据
export const API_getIntegratedQuestion = (id: number) => {
    return http<interviewDetail>({
		method: 'GET',
		url: `/integratedQuestion/getQuestion?id=${id}`,
	})
}

// 查看八股参考答案
export const API_getIntegrateAnswer = (id: number) => {
    return http<string>({
		method: 'GET',
		url: `/integratedQuestion/getAnswer?id=${id}`,
	})
}

export const API_getCategoryOfInter = (category: number) => {
    return http<interviewItem[]>({
		method: 'GET',
		url: `/integratedQuestion/getQuestionList?category=${category}`,
	})
}



// 查看八股参考答案
export const API_getComment = (category: number, categoryId: number) => {
    return http<string>({
		method: 'GET',
		url: `/comment/getComment?category=${category}&categoryId=${categoryId}`,
	})
}
